<template>
<div>
     <Modal v-model="modal" :title="title" :styles="{width:'600px',top:'50px'}">
        <Form ref='modifyForm' :model="obj" label-position="right" :rules="ruleValidate" :label-width="150" >
            <FormItem label="订单号" prop="orderNo">
                <Input  v-model="obj.orderNo" style="width:330px;"></Input>
            </FormItem>
            <!-- <FormItem label="订单类型" prop="orderType">
                <Select v-model="obj.orderType" style="width:330px">
                    <Option  value="1" >类型1</Option>
                    <Option  value="2" >类型2</Option>
                </Select>
            </FormItem> -->
            <FormItem label="销售方名称" prop="salesComName">
                <Input  v-model="obj.salesComName" style="width:330px;"></Input>
            </FormItem>
            <FormItem label="纳税人识别号" prop="salesComOrgCode">
                <Input  v-model="obj.salesComOrgCode" style="width:330px;"></Input>
            </FormItem>
            <!-- <FormItem label="总金额" prop="totleAmount" >
                <Input v-model="obj.totleAmount" style="width:330px;"></Input>
            </FormItem> -->

         </Form>
        
         <div slot="footer">
             <Button @click="cancel()">关闭</Button>
             <Button type="primary" @click="submit('add')" v-show="title=='添加订单'">
             添加</Button>
             <Button type="primary" @click="submit('update')" v-show="title=='修改订单'">
             修改</Button>
         </div>
     </Modal>
</div>
</template>
<script>
 export default {
     data (){
         return {
             modal:false,title:'添加订单',
             express:[{
                value:'顺丰快递',label:'顺丰快递'
             },{
                value:'EMS',label:'EMS'
             }],
             obj:{orderNo:'',orderType:'',salesComName:'',salesComOrgCode:'',totleAmount:0},
             ruleValidate:{
                 orderNo:[
                     { required: true, message: '订单号不能为空', trigger: 'blur' }
                 ],orderType:[
                     {required:true,message:'订单号不能为空',trigger:'change'}
                 ],salesComName:[
                     {required:true,message:'销售方名称不能为空',trigger:'blur'}
                 ],salesComOrgCode:[
                     {required:true,message:'销售方组织机构代码不能为空',trigger:'blur'}
                 ]
                 // ,totleAmount:[
                 //     {required:true,message:'总金额不能为空',trigger:'blur'}
                 // ]
             }
         }
     },methods:{
         showdata(params){
            this.modal=true;
            if(!params){
                this.obj={orderNo:'',orderType:'',salesComName:'',salesComOrgCode:'',totleAmount:0}
                this.title='添加订单'
            }else{
                this.title='修改订单'
                this.obj=JSON.parse(params);
                //this.obj.totleAmount=Number(params.totleAmount);
            }
            this.$refs['modifyForm'].resetFields();
         },
         submit(type){
             if(this.handleSubmit()){

                 var url='/incomeinvoice/addOrder';
                 if(type=='update'){
                     url='/incomeinvoice/editOrder'
                 }
                 console.log(this.obj)
                 this.axios.post(url,this.obj).then((res)=>{
                     //console.log(res);
                     if(res.errorCode==0){
                        //成功
                         this.modal=false;
                         this.obj={};
                         this.$Message.success('成功');
                         this.$emit('refresh');
                     }else{
                        //this.$Message.error(res.message);
                     }
                 }) 
                 return ;  
                 
             }
         },
         cancel(){
             this.modal=false;
         },handleSubmit () {
             var a=true;
             this.$refs['modifyForm'].validate((valid) => {
                 if (valid) {
                     //this.$Message.success('Success!');
                 } else {
                     //this.$Message.error('Fail!');
                     a=false;
                 }
             })
             return a;
         },
     },created(){
         this.$bus.on('bus_entryorder', this.showdata);
         
     },beforeDestroy(){
         this.$bus.off('bus_entryorder',this.showdata)
     }
 }
</script>
